<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<script type="text/javascript">
<!--
	function setCheckInfo(check_name, data_type, items, default_value,check_unit) {

		$("#dataType").val(data_type);
		if (data_type == "select" || data_type == "checkbox") {
			$("#trDatasource").show();
		
			$("#items").val(items);
			$("#defaultValue").val(default_value);
		} else {
			$("#trDatasource").hidden();
		}
		$("#checkName").val(check_name);
		$("#checkUnit").val(check_unit);
		$("#dataType").trigger('chosen:updated');
	}
//-->
</script>
<div class="header">
	<h3>巡检项</h3>
</div>
<form:form commandName="model" cssClass="validate"
	action="task/inspectTemplateCheck/save">
	<form:hidden path="id" />
	<form:hidden path="templateId" />
	<form:hidden path="ciId" />
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">名称：</td>
				<td class="td2"><form:input path="checkName"
						cssClass="required" /> &nbsp;&nbsp;同类别名称： <c:forEach
						items="${checkNames }" var="cn">
						<a
							onclick="setCheckInfo('${cn.check_name}','${cn.data_type}','${cn.items}','${cn.default_value}','${cn.check_unit }')">${cn.check_name}</a>&nbsp;
					</c:forEach>
				</td>
			</tr>
			<tr>
				<td class="td1">单位：</td>
				<td class="td2"><form:input path="checkUnit" /></td>
			</tr>

			<tr>
				<td class="td1">类型：</td>
				<td class="td2"><form:select path="dataType">
						<form:option value="string">字符串</form:option>
						<form:option value="number">数字</form:option>
						<form:option value="date">日期</form:option>
						<form:option value="checkbox">选择</form:option>
						<form:option value="select">自定义下拉选择</form:option>
						<form:option value="textarea">文本框</form:option>
					</form:select></td>
			</tr>
			<tr id="trDatasource" style="display:none">
				<td class="td1">数据源(请用"|"分割)：</td>
				<td class="td2" colspan="3"><form:textarea path="items" />
				</td>
			</tr>
			<tr>
				<td class="td1">默认值：</td>
				<td class="td2"><form:input path="defaultValue" />
				</td>
			</tr>
			<tr id="trRegex">
				<td class="td1">验证正则式：</td>
				<td class="td2"><form:input path="regex" /></td>
			</tr>
			<tr>
				<td class="td1">必填项：</td>
				<td class="td2"><form:checkbox path="notnull" />
				</td>
			</tr>
			<tr>
				<td class="td1">是否备注：</td>
				<td class="td2"><form:checkbox path="needRemark" />
				</td>
			</tr>
			<tr>
				<td class="td1">排序：</td>
				<td class="td2"><form:input path="orderNum" cssClass="number" />
				</td>
			</tr>
		</tbody>
	</table>

</form:form>
<isperp:buttonList>
	<button class="submit" onclick="isperp.submitForm();return false;">
		<span class="icon icon-save"></span>提交
	</button>
</isperp:buttonList>

<script type="text/javascript">
	function dataTypeChange() {
		var val = $("#dataType").val();
		if (val == "select" || val == "checkbox") {
			$("#trDatasource").show();
			var items = $("#items").val();
			if (!items) {
				$("#items").val("正常|异常");
				$("#defaultValue").val("正常");
			}

		} else {
			$("#trDatasource").hide();
		}
		if (val != "string") {
			$("#trRegex").hide();
		} else {
			$("#trRegex").show();
		}
	}

	dataTypeChange();
	$("#dataType").change(function() {
		dataTypeChange();

	});
</script>
